import jdk.nashorn.api.scripting.ScriptObjectMirror;

import javax.swing.tree.TreeNode;

public class Test {
    int count = 0;
    int size(TreeNode root){

        if (root == null){
            return 0;
        }
        count++;
        size(root.left);
        size(root.right);
        return count;

    }

    int getLeafNodeCount(TreeNode root){
        if (root == null){
            return 0;
        }
        if (root.left == null && root.right == null){
            return 1;
        }
        return getLeafNodeCount(root.leaf) + getLeafNodeCount(root.right);
    }

    int count = 0;
    int getLeafNodeCount1(TreeNode root){
        if (root == null){
            return 0;
        }
        if (root.left == null && root.right == null){
            count++;
        }
        getLeafNodeCount(root.left);
        getLeafNodeCount(root.right);
        return count;
    }

    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        if (root == null){
            return null;
        }
        if (root == p || root == q){
            return root;
        }
        TreeNode left = lowestCommonAncestor(root.left,p,q);
        TreeNode right = lowestCommonAncestor(root.right,p,q);
        if (left == null){
            return right;
        }else if (right == null){
            return left;
        }else{
            return root;
        }

    }

    public void print(int n){
        if (n < 10){
            System.out.println(n);
        }else {
            print(n/10);
            System.out.println(n%10 + " +");
        }
    }
}
